package org.example.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 统一  返回结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result implements Serializable {
    //状态码    200:正常  404:url错误  400:参数接收(类型)异常  405:请求方式不对应   500:程序bug  503:没有完全启动
    private Integer code;
    //提示信息
    private String msg;

    //操作是否成功
    private Boolean flag;

    //返回的结果
    private Object data;

    public static Result success(){
        return new Result(200,"操作成功",true,null);
    }
    public static Result success(Integer code,String msg){
        return new Result(200,msg,true,null);
    }
    public static Result success(Object data){
        return new Result(200,"操作成功",true,data);
    }
    public static Result success(String msg,Object data){
        return new Result(200,msg,true,data);
    }

    public static Result fail(){
        return new Result(500,"操作失败",false,null);
    }
    public static Result fail(String msg){
        return new Result(500,msg,false,null);
    }
    public static Result fail(Integer code,String msg){
        return new Result(code,msg,false,null);
    }
    public static Result fail(Integer code,Object data){
        return new Result(code,"操作成功",false,data);
    }
    public static Result fail(Integer code,String msg,Object data){
        return new Result(code,msg,false,data);
    }

}
